package com.scs.application.modules.fsd.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.fsd.entity.FsdUsersChestGroup;
import com.scs.application.modules.fsd.service.UsersChestGroupService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description: 用户柜组权限
 */
@RestController
@RequestMapping("/back_front/users_chestGroups")
public class UsersChestGroupController extends CrudController<UsersChestGroupService, FsdUsersChestGroup> {

    @GetMapping(value = "/getChestGroupsByUserService")
    public RestResult getChestGroupsByUser(@RequestParam("id") String id){
        return RestResult.ok("获取该用户所拥有的权限成功",service.getChestGroupsByUser(id));
    }

    @PostMapping(value = "/changeChestGroupsByUserService")
    public RestResult changeChestGroupsByUser(@RequestBody Map<String, String> map){
        if(service.changeChestGroupsByUser(StringUtils.stringArryExtract(map.get("idAry"),"chestGroupId"),map.get("id")))
            return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }

    @GetMapping(value = "/getUsersByChestGroupService")
    public RestResult getUsersByChestGroup(@RequestParam("id") String id){
        return RestResult.ok("获取该智能柜组所拥有的用户成功",service.getUsersByChestGroup(id));
    }

    @PostMapping(value = "/changeUsersByChestGroupService")
    public RestResult changeUsersByChestGroup(@RequestBody Map<String, String> map){
        if(service.changeUsersByChestGroup(StringUtils.stringArryExtract(map.get("idAry"),"userId"),map.get("id")))
            return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }
}
